package com.epfresh.supplier.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.epfresh.api.utils.MarketPermissionUtil;
import com.epfresh.supplier.Listener.IndexIconOnClickListener;
import com.epfresh.supplier.R;
import com.epfresh.supplier.entity.HomePart;
import com.epfresh.supplier.widget.CommonRecyclerAdapter;
import com.epfresh.supplier.widget.ViewHolder;

import java.util.List;

public class HomePart1Adapter extends CommonRecyclerAdapter<HomePart> {
    private IndexIconOnClickListener indexIconOnClickListener;
    private boolean isShowRedPoint = false;

    public HomePart1Adapter(Context context, List<HomePart> datas) {
        super(context, datas, R.layout.home_part);
    }

    public void setDatas(List<HomePart> datas) {
        super.setData(datas);
    }

    public void setShowRedPoint(boolean isShowRedPoint) {
        this.isShowRedPoint = isShowRedPoint;
    }

    public void setListener(IndexIconOnClickListener indexIconOnClickListener) {
        this.indexIconOnClickListener = indexIconOnClickListener;
    }

    @Override
    public void convert(ViewHolder holder, final HomePart item, int position) {
        ImageView pic = holder.getView(R.id.iv_pic);
        ImageView ivPoint = holder.getView(R.id.iv_point);
        RelativeLayout rlIcon = holder.getView(R.id.rl_icon);
        switch (item.getName()) {
            case MarketPermissionUtil.marketOis:
                pic.setBackgroundResource(R.mipmap.entry_registration);
                ivPoint.setVisibility(View.GONE);
                holder.setText(R.id.tv_name, "进场登记");
                break;
            case MarketPermissionUtil.marketDetection:
                pic.setBackgroundResource(R.mipmap.presentation);
                ivPoint.setVisibility(View.GONE);
                holder.setText(R.id.tv_name, "检测报告");
                break;
            case MarketPermissionUtil.marketMyDetection:
                pic.setBackgroundResource(R.mipmap.mycontract);
                ivPoint.setVisibility(View.GONE);
                holder.setText(R.id.tv_name, "我的合同");
                break;
            case MarketPermissionUtil.marketMyCar:
                pic.setBackgroundResource(R.mipmap.mycar);
                ivPoint.setVisibility(View.GONE);
                holder.setText(R.id.tv_name, "我的车辆");
                break;
            case MarketPermissionUtil.marketPreRegistration:
                pic.setBackgroundResource(R.mipmap.register);
                ivPoint.setVisibility(View.GONE);
                holder.setText(R.id.tv_name, "预登记");
                break;
            case MarketPermissionUtil.marketPay:
                pic.setBackgroundResource(R.mipmap.pay);
                if (isShowRedPoint) {
                    ivPoint.setVisibility(View.VISIBLE);
                } else {
                    ivPoint.setVisibility(View.GONE);
                }
                holder.setText(R.id.tv_name, "缴费");
                break;
        }
        rlIcon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (indexIconOnClickListener != null) indexIconOnClickListener.onclick(item.getName());
            }
        });

    }
}
